<?php
// application/lib/Cache.php
/**
 * demo-zf application
 *
 * lib\Lib_Cache
 *
 * This class is used as helper for cache
 *
 * @author Adam Pilacki <adam.pilacki@gmail.com>
 */
class Lib_Cache
{
    /* cache ids defs */
    const INI_FINAL_ID = 'final';
    const INI_APPLICATION_ID = 'app';
    const INI_DB_ID = 'db';

    /**
     * Prepares and returns cache for ini files
     * This method helps to avoid code repeat
     *
     * @param int $lifetime
     * @param array $masterFiles
     * @param string $prefix
     * @param boolean $enableCache
     * @return Zend_Cache_Frontend_File
     */
    public static final function getCacheForIni($lifetime, array $masterFiles, $prefix, $enableCache = true)
    {
        $frontendOptions = array(
            'lifetime' => $lifetime, /* seconds */
            'automatic_serialization' => true,
            'caching' => $enableCache,
            'master_files' => $masterFiles,
        );
        $backendOptions = array(
            'cache_dir' => APPLICATION_PATH . '/../cache/configs',
            'file_name_prefix' => $prefix,
        );
        return Zend_Cache::factory('File', 'File', $frontendOptions, $backendOptions);
    }
}